<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@include file="/WEB-INF/webpage/common/taglibs.jspf"%>
<!DOCTYPE html>
<html>
<head>
  <title><spring:message code="sys.user.title" /></title>
  <meta name="decorator" content="grid-select"/>
  <html:css  name="iCheck,Validform,jquery-ztree,easy-ui"/>
  <html:js  name="iCheck,Validform,jquery-ztree,easy-ui,public-js"/>
  <style type="text/css">.row{margin:0;}</style>
</head>
<body title="<spring:message code="sys.user.title" />">
<form:form id="usersForm" modelAttribute="data" method="post" 
	class="form-horizontal" action="${adminPath}/activiti/deploy/saveUserGroup">
	<form:hidden path="ids" nested="false"/>
	<form:hidden path="groupId" nested="false" defaultValue="${param.groupId}"/>
</form:form>
	<grid:grid id="userGridId" url="${adminPath}/sys/user/ajaxListUser"
		gridSetting="{gridComplete:completeMethod}" onSelectRow="selectRow">
		<grid:column label="sys.common.key" hidden="true"   name="id" width="100"/>
		<grid:query name="orgId"  queryMode="hidden" />
	    <grid:column label="sys.user.realname"  name="realname"  query="true"  condition="like" width="60" />
	    <grid:column label="sys.user.username"  name="username"  query="true" condition="like"  width="60" />
	    <grid:column label="sys.user.organization.name"  name="orgName"/>
	    <grid:column label="sys.user.email"  name="email"  width="60"/>
	    <grid:column label="sys.user.phone"  name="phone"  query="true"  condition="like"  width="60"/>
		<grid:toolbar  function="search"/>
		<grid:toolbar  function="reset"/>
	</grid:grid>
<script type="text/javascript">

var userIds = JSON.parse('${userIds}');
var gridId = 'userGridIdGrid';
var jqg = 'jqg_userGridIdGrid_';

/**
 * @function 加载完成后触发 .<br>
 * @date 2018/5/24.<br>
 * @author zcg .<br>
 */
function completeMethod(){
	 var datas =  $("#"+gridId).jqGrid("getRowData"); 
		$.each(datas,function(index,item){
			var id = item.id;
			var flag = $.inArray(id, userIds);
			if(flag!=-1){
				$("#"+gridId).jqGrid("setSelection", id,false);
				$("#"+jqg+id).attr("disabled","disabled");
			}
		});
 }

/**
 * @function 已导入的不允许再次选择 .<br>
 * @date 2018/5/24.<br>
 * @author zcg .<br>
 */
function selectRow(id){
	 var flag = $.inArray(id, userIds);
	 if(flag!=-1){
		 $("#"+gridId).jqGrid("setSelection", id,false);
	 }
}

/**
 * @description 回调函数，在编辑和保存动作时，供openDialog调用提交表单。.<br>
 * @date 2018/3/29.<br>
 * @author zcg .<br>
 */
function doSubmit(func){
	callFunc=func;
   	validateForm.ajaxPost();
}

/**
 * @description 提交表单.<br>
 * @date 2018/3/29.<br>
 * @author zcg .<br>
 */
$(document).ready(function() {
       	validateForm = $("#usersForm").Validform({
       	ajaxPost:true,
		beforeSubmit:function(curform){
			loadIndex = openLoad();
			var pushIds = new Array();
			var ids = $("#"+gridId).jqGrid('getGridParam','selarrrow');
			$.each(ids,function(i,item){
				var flag = $.inArray(item, userIds);
				if(flag==-1){
					pushIds.push(item);
				}
			});
			$('#ids').val(pushIds.join(','));
			return true;	
		},callback:function(result){
			 closeLoad(loadIndex);
			 callFunc(result);
		}
	});
});
	
/**
* @description 打开layer的加载层.<br>
* @returns 返回打开的阴影层的下标.<br>
* @author zcg.<br>
*/
function openLoad(){
	return top.layer.load(2, {
		shade: [0.3,'#fff'],
		shadeClose : false
	});
}

/**
* @description 关闭layer的加载层.<br>
* @returns 返回打开的阴影层的下标.<br>
* @author zcg.<br>
*/
function closeLoad(index){
	top.layer.close(index);
}

</script>
</body>
</html>